<template>
<div>
  <div style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 29px;padding: 20px">
    江 西 省 地 方 标 准 报 批 表
  </div>
  <div style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 21px;margin-bottom: 10px;">
    （试行）
  </div>
  <t-form labelAlign="top" ref="form" :data="formData"  class="step-form table-form"
          labelWidth="140px">
    <t-row>
      <t-col :span="2" class="title">标准名称</t-col>
      <t-col :span="4">
        <t-form-item name="projectName">
          {{ formData.projectName }}
        </t-form-item>
      </t-col>
      <t-col :span="2" class="title"><span class="require">*</span>标准号</t-col>
      <t-col :span="4">
        <t-form-item name="standardNum">
          {{ formData.standardNum }}
        </t-form-item>
      </t-col>

    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>报批日期</t-col>
      <t-col :span="4">
        <t-form-item name="submitDate">
          {{ formData.submitDate }}
        </t-form-item>
      </t-col>
      <t-col :span="2" class="title"><span class="require">*</span>批复报批时间</t-col>
        <t-col :span="4">
          <t-form-item name="replyDate">
            {{  formData.replyDate }}
          </t-form-item>
        </t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>任务来源<br/>计划项目编号</t-col>
      <t-col :span="10">
        <t-form-item name="projectNum">
          {{  formData.projectNum }}
        </t-form-item>
      </t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>主要起草单位</t-col>
      <t-col :span="10">
        <!-- {{ formData.unitId | filterByTree(deptMenuOptions, children = "children", id = "unitId", label = "unitName")}} -->
        <standard-company ref="standard-company" tableSize="small" v-model="formData.draftUnits" :editOpen="false"></standard-company>
      </t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>项目负责人</t-col>
      <t-col :span="4">
        <t-form-item name="projectLeader">
          {{ formData.projectLeader }}
        </t-form-item>
      </t-col>
      <t-col :span="2" class="title"><span class="require">*</span>联系电话</t-col>
      <t-col :span="4">
        <t-form-item name="phone">
          {{ formData.phone }}
        </t-form-item>
      </t-col>
    </t-row>
    <t-row>
      <t-col :span="2" class="title"><span class="require">*</span>相关附件</t-col>
      <t-col :span="10">
        <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData">
          <template #id="{row, rowIndex}">
            {{ rowIndex+1 }}
          </template>
          <template #c1="{row}">
            <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
            <div v-else>{{ row.c1 }}</div>
          </template>
          <template  #op="{row}">
            <file-upload
                v-if="['projectBPB'].includes(row.moduleKey) && $store.state.user.roles.includes('dwsby')"
                @success="uploadSuccess"
                tips="限制pdf、图片"
                accept="application/pdf,image/*"
                v-model="row.fileIds"
                :moduleKey="row.moduleKey"
                :fileList="row.fileLists"
                :multiple="true"
              >
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon" />
                  点击上传
                </t-button>
              </file-upload>
              <div v-else v-for="(item,index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url" >
                  {{item.name}}
                </a>
              </div>
          </template>
        </t-table>
      </t-col>
    </t-row>
  </t-form>
</div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import standardCompany from "@/pages/bzh/standard/components/standard-company.vue";
import InnerHtml from "@/components/InnerHtml/index.vue";
import memberList from "../../../components/member-list.vue";
import {getFiles} from "@/api/common";
import FileUpload from '@/components/FileUpload/index.vue';



export default {
  name: "submit-detail",
  components:{
    standardCompany,
    InnerHtml,
    memberList,
    FileUpload,
  },
  data(){
    return {
      projectFileData: [
        {
          id: 1,
          c1: "盖章后的报批表",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBPB",
          require: true,
        },
        {
          id: 2,
          c1: "报批稿",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBPG",
          require: true,
        },
        {
          id: 3,
          c1: "编制说明",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBZSM",
          require: true,
        },
        {
          id: 4,
          c1: "批复报批文件",
          c2: "否",
          fileIds: [],
          fileLists: [],
          moduleKey: "bzhbpblb",
          require: false,
        },
        {
          id: 5,
          c1: "其他",
          c2: "否",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectOther",
          require: false,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      file_domain: VITE_FILE_DOMAIN,
      deptMenuOptions: [],
      formData: {
        localId: null,
        taskSource: '',
        projectNum: '',
        projectLeader: '',
        phone: '',
        unitId: null,
        draftUnits: [],
        submitDate: '',
        replyDate: '',
      },
    }
  },
  props: {
    objId: [String, Number],
    reviewOpen: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  created() {
  },
  methods: {
    getObj() {
      this.$api.bzh.submit.getBySuggestId(this.objId).then(response => {
        if (response.data.createUserId === Number(this.$store.state.user.userId)) {
          this.isMyProject = true;
        }
        Object.assign(this.formData, response.data);
        getFiles(response.data.id).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }).catch((e) => {
        this.$message.error(e.toString());
      });
      this.$api.bzh.standard.getApplyBySuggestId(this.objId).then(response => {
        this.formData.projectName = response.data.projectName;
        this.formData.draftUnits = response.data.draftUnits;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    uploadSuccess(ids) {
      this.$api.bzh.submit
        .updateBase({
          id: this.formData.id,
          sysAttMainVo: {
            sysAttMainIds: ids,
          },
        })
        .then((val) => {
          this.$message.success('上传成功');
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
  }
}
</script>

<style scoped>

</style>
